
#include <BoseCmd.h>

#include <BoseAidlService.h>
#include <com/bose/IBoseCmd.h>
#include <com/bose/BpBoseCmd.h>


#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>

#undef TAG
#define TAG "BOSECMD_AIDL"
#ifdef __ANDROID__
#define BOSE_LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
#define BOSE_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define BOSE_LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
#define BOSE_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
#else
#define BOSE_LOGI(str, ...) do{printf("BOSE_AIDL ");printf(str,##__VA_ARGS__);printf("\n");}while(0)
#define BOSE_LOGD(str, ...) do{printf("BOSE_AIDL ");printf(str,##__VA_ARGS__);printf("\n");}while(0)
#define BOSE_LOGW(str, ...) do{printf("BOSE_AIDL ");printf(str,##__VA_ARGS__);printf("\n");}while(0)
#define BOSE_LOGE(str, ...) do{printf("BOSE_AIDL ");printf(str,##__VA_ARGS__);printf("\n");}while(0)
#endif

using namespace android;
using namespace com::bose;


int main(int argc, char * argv[]) {
    BoseAidlServiceCallbacks cb {BoseCmd::call_system,
                                 BoseCmd::call_popen};
    if(argc >2) {
        BOSE_LOGI("unused %s", argv[1]);
    }

    sp<ProcessState> proc(ProcessState::self());
    sp<IServiceManager> sm = defaultServiceManager();
    sm->addService(String16("bosecmd_sys"), new BoseAidlService(&cb));
    BOSE_LOGI("resgistered aidl service bosecmd_sys");
    ProcessState::self()->setThreadPoolMaxThreadCount(2);
    ProcessState::self()->startThreadPool();
    IPCThreadState::self()->joinThreadPool();

    BOSE_LOGD("exit");
    return 0;
}
